package com.medicine.manage.service.impl;

import java.util.List;
import com.medicine.common.utils.DateUtils;
import com.medicine.common.utils.SecurityUtils;
import com.medicine.manage.block.service.IBlockProcessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import com.medicine.manage.mapper.ExpressMapper;
import com.medicine.manage.domain.Express;
import com.medicine.manage.service.IExpressService;

/**
 * 配送Service业务层处理
 * 
 * @author admin
 * @date 2024-10-13
 */
@Service
public class ExpressServiceImpl implements IExpressService 
{
    @Autowired
    private ExpressMapper expressMapper;

    @Autowired
    @Qualifier("blockProcessExpressService")
    private IBlockProcessService blockProcessExpressService;

    /**
     * 查询配送
     * 
     * @param id 配送主键
     * @return 配送
     */
    @Override
    public Express selectExpressById(Long id)
    {
        return expressMapper.selectExpressById(id);
    }

    /**
     * 查询配送列表
     * 
     * @param express 配送
     * @return 配送
     */
    @Override
    public List<Express> selectExpressList(Express express)
    {
        return expressMapper.selectExpressList(express);
    }

    /**
     * 新增配送
     * 
     * @param express 配送
     * @return 结果
     */
    @Override
    public int insertExpress(Express express)
    {
        express.setCreateBy(SecurityUtils.getLoginUser().getUserId().toString());
        express.setCreateTime(DateUtils.getNowDate());
        int result = expressMapper.insertExpress(express);
        blockProcessExpressService.insertProcessObj(express, SecurityUtils.getLoginUser().getDeptId(), SecurityUtils.getLoginUser().getUserId());
        return result;
    }

    /**
     * 修改配送
     * 
     * @param express 配送
     * @return 结果
     */
    @Override
    public int updateExpress(Express express)
    {
        express.setUpdateBy(SecurityUtils.getLoginUser().getUserId().toString());
        express.setUpdateTime(DateUtils.getNowDate());

        int result = expressMapper.updateExpress(express);
        Express e = expressMapper.selectExpressById(express.getId());
        blockProcessExpressService.updateProcessObj(e, SecurityUtils.getLoginUser().getDeptId(), SecurityUtils.getLoginUser().getUserId());
        return result;
    }

    /**
     * 批量删除配送
     * 
     * @param ids 需要删除的配送主键
     * @return 结果
     */
    @Override
    public int deleteExpressByIds(Long[] ids)
    {
        return expressMapper.deleteExpressByIds(ids);
    }

    /**
     * 删除配送信息
     * 
     * @param id 配送主键
     * @return 结果
     */
    @Override
    public int deleteExpressById(Long id)
    {
        return expressMapper.deleteExpressById(id);
    }
}
